Skip to content

fix(cli): don't count a trailing newline as a hidden tool-result line - #3277

Open
XAE-A-Xii wants to merge 1 commit into
HKUDS:devfrom
XAE-A-Xii:fix/cli-tool-result-trailing-newline
Open

XAE-A-Xii wants to merge 1 commit into
HKUDS:devfrom
XAE-A-Xii:fix/cli-tool-result-trailing-newline

Conversation

@XAE-A-Xii

Copy link
Copy Markdown

Description

The CLI's inline tool-result preview counted a trailing newline as a hidden line. truncate_for_display (deeptutor_cli/_tool_result.py) split the body on "\n", so the empty string after a final newline counted as a line. Tool output that exactly fits the preview, for example 10 lines ending in \n (which is how stdout usually ends), reported hidden=1, and common.py:_render_tool_result printed +1 more line; run /show N to expand with nothing left to expand. The collapsed preview (head_lines=0) disagreed with itself too: "a\nb\n" counted 3 lines, but "a\nb" counted 2.

                              10 lines + "\n" -> hidden   "a\nb\n", head_lines=0
before (dev)                  1                           ('', 3)
after                         0                           ('', 2)

Both paths now share a small _lines() helper that drops the newline ending the last line before splitting. A genuinely blank last line still counts ("a\n\n" → 2), and the visible preview text is unchanged apart from that trailing newline.

Related Issues

  • None filed; this is a small, self-contained fix.

Module(s) Affected

  • agents
  • api
  • config
  • core
  • knowledge
  • logging
  • services
  • tools
  • utils
  • web (Frontend)
  • docs (Documentation)
  • scripts
  • tests
  • Other: deeptutor_cli

Checklist

  • This PR targets dev (not main — see the base-branch selector above).
  • I have read and followed the contribution guidelines.
  • My code follows the project's coding standards.
  • I have run pre-commit run --all-files and fixed any issues.
  • I have added relevant tests for my changes.
  • I have updated the documentation (if necessary). (Not needed.)
  • My changes do not introduce any new security vulnerabilities.

Additional Notes

There were no tests for truncate_for_display, so this adds tests/cli/test_tool_result.py with four cases:

  • output that fits hides nothing, even with a trailing newline;
  • the hidden count is the same with or without a trailing newline;
  • the collapsed preview counts lines the same way;
  • a real blank last line still counts.

Before the fix all 4 fail. Mutations are caught too: dropping the removesuffix fails 4, and putting back the old _line_count fails 2.

$ python -m pytest tests/cli -q
188 passed, 1 skipped          (dev: 184 passed, 1 skipped; the 4 extra are the new tests)

pre-commit run --files on both changed files passes every hook. --all-files fails mypy on dev itself in services/embedding/adapters/volcengine.py, from #1015, which this PR doesn't touch.

🤖 Generated with Claude Code

@github-actions github-actions Bot added backend Python runtime, capabilities, tools, API & CLI bug Something isn't working labels Dec 5, 2026
`truncate_for_display` split the body on "\n", so the empty string
after a final newline counted as a line. Tool output that exactly fit
the preview (10 lines ending in "\n", typical stdout) reported
hidden=1, and the CLI printed "+1 more line; run /show N to expand"
with nothing to expand. The collapsed preview (`head_lines=0`) counted
"a\nb\n" as 3 lines but "a\nb" as 2.

Both paths now share `_lines()`, which drops the newline that ends the
last line before splitting; a genuinely blank last line ("a\n\n")
still counts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@XAE-A-Xii
XAE-A-Xii force-pushed the fix/cli-tool-result-trailing-newline branch from 1cc2b0d to 738e7c4 Compare December 5, 2026 12:15
@ZQR1101 ZQR1101 self-assigned this Dec 5, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Python runtime, capabilities, tools, API & CLI bug Something isn't working

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants